/**
 * Copyright (C) 2017 - 2020 https://github.com/joewee
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bifrost.model.sap;

import com.bifrost.entity.Order;
import com.bifrost.entity.OrderReturn;
import com.thoughtworks.xstream.annotations.XStreamAlias;

import java.io.Serializable;
import java.math.BigDecimal;

/**
 *支付信息
 *
 *@author joewee
 *@version 1.0.0
 *@Date 2018/5/18 12:45
 */
@XStreamAlias("ITEM8")
public class Payment  extends BaseXml implements Serializable{
    public static final String TENDER_TYPE_CODE_WEIXIN = "27";


    /**
     *序号
     * */
    @XStreamAlias("TENDERNUMBER")
    private Integer  tenderNumber = 1;
    /**
     *支付方式代码
     * */
    @XStreamAlias("TENDERTYPECODE")
    private String tenderTypeCode = TENDER_TYPE_CODE_WEIXIN;
    /**
     *支付金额
     * */
    @XStreamAlias("TENDERAMOUNT")
    private BigDecimal tenderAmount;
    /**
     *收单行科目
     * */
    @XStreamAlias("ACCOUNTNUMBER")
    private String accountNumber = "";
    /**
     *手续费
     * */
    @XStreamAlias("REFERENCEID")
    private String referenceId="0";

    public Payment() {

    }
    public <T> Payment(T o) {
        if(o instanceof Order) {
            Order order = (Order) o;
            this.tenderAmount = order.getOrderTotal();
        } else if(o instanceof OrderReturn) {
            OrderReturn orderReturn = (OrderReturn)o;
            this.tenderAmount = orderReturn.getRefundTotal();
        } else {
            throw new IllegalArgumentException("参数：" + o + " 类型错误，期望类型为Order或则OrderReturn");
        }
    }

    public Integer getTenderNumber() {
        return tenderNumber;
    }

    public void setTenderNumber(Integer tenderNumber) {
        this.tenderNumber = tenderNumber;
    }

    public String getTenderTypeCode() {
        return tenderTypeCode;
    }

    public void setTenderTypeCode(String tenderTypeCode) {
        this.tenderTypeCode = tenderTypeCode;
    }

    public BigDecimal getTenderAmount() {
        return tenderAmount;
    }

    public void setTenderAmount(BigDecimal tenderAmount) {
        this.tenderAmount = tenderAmount;
    }

    public String getAccountNumber() {
        return accountNumber;
    }

    public void setAccountNumber(String accountNumber) {
        this.accountNumber = accountNumber;
    }

    public String getReferenceId() {
        return referenceId;
    }

    public void setReferenceId(String referenceId) {
        this.referenceId = referenceId;
    }
}
